//
//  AnimationHelper.m
//  LLP
//
//  Created by Porcellio on 10/16/12.
//  Copyright (c) 2012 Porcellio. All rights reserved.
//

#import "AnimationHelper.h"

#define RADIANS(degrees) ((degrees * M_PI) / 180.0)

@implementation AnimationHelper

+ (void)addWobbleAnimationWithView:(UIView *)view {
        
    CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
    CGFloat wobbleAngle = 0.06f;
    NSValue* valLeft = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(wobbleAngle, 0.0f, 0.0f, 1.0f)];
    NSValue* valRight = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(-wobbleAngle, 0.0f, 0.0f, 1.0f)];
    animation.values = [NSArray arrayWithObjects:valLeft, valRight, nil];
    animation.autoreverses = YES;
    animation.duration = 0.125;
    animation.repeatCount = HUGE_VALF;
    
    [view.layer addAnimation:animation forKey:@"wobble"];
}

+ (void)removeWobbleAnimationWithView:(UIView *)view {
    
    view.transform = CGAffineTransformIdentity;
    [view.layer removeAnimationForKey:@"wobble"];
}

+ (void)addScaleAnimationWithView:(UIView *)view {

    [UIView animateWithDuration:.3f animations:^{
       
        view.transform = CGAffineTransformMakeScale(1.2f, 1.2f);
    }];
}

+ (void)removeScaleAnimationWithView:(UIView *)view {

    [UIView animateWithDuration:.3f animations:^{
       
        view.transform = CGAffineTransformIdentity;
    }];
}

@end
